package com.qianfeng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.ChargeProject;
import com.qianfeng.mapper.ChargeProjectMapper;
import com.qianfeng.service.ChargeProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ChargeProjectServiceImpl implements ChargeProjectService {
    @Autowired
    private ChargeProjectMapper chargeProjectMapper;

    @Override
    public void addChargeProject(ChargeProject chargeProject) {
        chargeProjectMapper.addChargeProject(chargeProject);
    }

    @Override
    public void updateChargeProject(ChargeProject chargeProject) {
        chargeProjectMapper.updateChargeProject(chargeProject);
    }

    @Override
    public void deleteChargeProject(Integer cpId) {
        chargeProjectMapper.deleteChargeProject(cpId);
    }

    @Override
    public ChargeProject getChargeProjectById(Integer cpId) {
        return chargeProjectMapper.getChargeProjectById(cpId);
    }

    @Override
    public Page getChargeProjectPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<ChargeProject> chargeProjectList = chargeProjectMapper.getChargeProjectList();
        PageInfo<ChargeProject> pageInfo = new PageInfo<>(chargeProjectList);
        page.setObj(pageInfo.getList());
        page.setPageCount(pageInfo.getPages());
        page.setHasNext(pageInfo.isHasNextPage());
        return page;
    }

    @Override
    public List<ChargeProject> getChargeProjectList() {
        return chargeProjectMapper.getChargeProjectList();
    }
}
